<%@page contentType="text/html; UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>用户登录</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"/>
    <script src="${pageContext.request.contextPath}/back/statics/js/jquery-1.8.3.min.js"></script>

</head>
<body >
<style>
    body{
        background-image: url("statics/images/login-bg.jpg");
        background-size: 100%;
        background-repeat: no-repeat;

    }
</style>


<div class="container-fluid">


    <%--用户注册--%>
    <div class="row" style="margin-top: 100px; margin-bottom: 30px">
        <div class="col-sm-4 col-sm-offset-4">
            <h1 class="text-center">用户登录</h1>
        </div>
    </div>

    <%--完成表单--%>
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4">

            <form id="inputForm">
                <div class="form-group">
                    <label for="name">用户名:</label>
                    <input type="text" class="form-control" name="name" id="name" placeholder="请输入用户名...">
                </div>
                <div class="form-group">
                    <label for="password">密码:</label>
                    <input type="password" name="password" class="form-control" id="password" placeholder="请输入密码...">
                </div>
                <div class="form-group">
                    <label for="identity">身份:</label>
                    <select name="identity" id="identity" style="width: 200px;" class="form-control">
                        <option value="admin">管理员</option>
                        <option value="teacher">老师</option>
                        <option value="student">学生</option>
                    </select>



                </div>
                <div class="form-group">
                    <label for="code">验证码:</label>
                    <div>
                        <input type="text" name="code" class="form-control" style="height:48px;width: 52%;float: left;"
                               id="code" placeholder="请输入验证码....">
                        <img src="${pageContext.request.contextPath}/login/getImage" id="image"
                             style="height:48px;float: right;" alt="">
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-danger" id="logBtn"
                        style="margin-top:40px;width: 30%;margin-left: 150px; ">登录
                </button>

            </form>

        </div>
    </div>

</div>

</body>
</html>
<script>









    $(function () {
        //获取图片标签的节点对象，为其绑定单击事件
        $("#image").click(function () {
            $("#image").attr("src","${pageContext.request.contextPath}/login/getImage?id="+Math.random());
        });


        //获取按钮节点，绑定单击时间
        $("#logBtn").click(function () {


            var name= $.trim($('#name').val());
            var password=$.trim($("#password").val());
            var code=$.trim($("#code").val());
            var ident=$('#identity').val();



            $.post("${pageContext.request.contextPath}/login/login",{
                    name:name,
                    password:password,
                    code:code,
                    ident:ident
                },
                function(data,status){
                    alert("数据: \n" + data + "\n状态: " + status);
                    if(data !=null)
                    {
                        if(data=="teacher"){
                            location.href="${pageContext.request.contextPath}/back/teacher/tea.jsp";
                        }else if(data=="student"){
                        location.href="${pageContext.request.contextPath}/back/student/stu.jsp";
                        }else if(data=="admin"){
                            location.href="${pageContext.request.contextPath}/back/main/index.jsp";
                        }else if(data=="error"){
                            location.href="${pageContext.request.contextPath}/back/404.jsp";
                        }
                       // location.reload();
                    }
                    else
                    {
                        alert('操作失败');
                    }
                });
        });
        });


</script>